//
//  FXTBaseViewController.m
//  OfferJob
//
//  Created by 郑州动力无限科技 on 2017/6/30.
//  Copyright © 2017年 郑州动力无限科技. All rights reserved.
//

#import "FXTBaseViewController.h"
#import "IQKeyboardManager.h"
#import "IQKeyboardReturnKeyHandler.h"
#define  kMessageTag 1000
#define  kPicTag  1001
@interface FXTBaseViewController ()
@property(nonatomic,assign) float scale;
@end

@implementation FXTBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _scale=1.0;
    if ([[UIScreen mainScreen] bounds].size.height > 480)
    {
        _scale = [[UIScreen mainScreen] bounds].size.height / 568.0;
    }
  
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[UIColor whiteColor];
    [[UINavigationBar appearance]setBarTintColor:RGBCOLOR(40,138,228)];
    self.navigationController.navigationBar.translucent = NO;
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self dependOnKindToViewShow];
    
    [IQKeyboardManager sharedManager].enable=YES;
    [IQKeyboardManager sharedManager].enableAutoToolbar=YES;
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
    [[IQKeyboardManager sharedManager] setToolbarDoneBarButtonItemText:@"完成"];
}
#pragma mark - Private Methods
-(void)dependOnKindToViewShow {
    FXTNavType navType =[self getNavType];
    switch (navType) {
        case FXTNavTypeNone:
            self.navigationController.navigationBar.hidden =YES;
            break;
        case FXTNavTypeOnlyTitle:
            self.navigationController.navigationBar.hidden =NO;
            [self customNavigationTitleView];
            
            break;
        case FXTNavTypeNoRightItem:
            self.navigationController.navigationBar.hidden =NO;
            [self customNavigationLeftItem];
            [self customNavigationTitleView];
            
            break;
        case FXTNavTypeAll:
            self.navigationController.navigationBar.hidden =NO;
            [self customNavigationTitleView];
            [self customNavigationRighItem];
            [self customNavigationLeftItem];
            break;
        case FXTNavTypeOnlyRightItem:
            self.navigationController.navigationBar.hidden =NO;
            [self customNavigationRighItem];
            break;
        case FXTNavTypeNoLeftItem:
            self.navigationController.navigationBar.hidden =NO;
            [self customNavigationTitleView];
            [self customNavigationRighItem];
           break;
        default:
            break;
    }
    
}

-(UIView *)getView:(CGRect)rect
{
    UIView *viewT=[[UIView alloc]initWithFrame:rect];
    viewT.backgroundColor=[UIColor colorWithRed:216.0/255.0 green:216.0/255.0 blue:216.0/255.0 alpha:1];
    
    return viewT;
}
//定制导航栏上的titleView
- (void)customNavigationTitleView
{
    NSString *titleStr =[self customNavigationTitleViewTitleStr];
    UILabel *label = [FXTCustomViewFactory createLabel:CGRectMake(0, 5, 100, 34) title:titleStr color:[UIColor whiteColor] font:[UIFont systemFontOfSize:19 *kAppScale] textAlignment:NSTextAlignmentCenter];
    self.navigationItem.titleView = label;
}

//定制导航栏左边的按钮
- (void)customNavigationLeftItem
{
    UIButton *leftButton =[UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(-10, 0, 30, 34);
    [leftButton setImage:[UIImage imageNamed:@"icon_jiantou"] forState:UIControlStateNormal];
    
    [leftButton addTarget:self action:@selector(navigationLeftButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftItem;
}

//定制导航栏右边的按钮
- (void)customNavigationRighItem
{
    NSString *titleStr =[self customNavigationRightItemTitle];
    
    UIButton * rightButton = [FXTCustomViewFactory  createButton:CGRectMake(0, 0, 80, 30) title:titleStr Image:[UIImage imageNamed:@"icon_rightItemBg"]];
    rightButton.titleLabel.font =[UIFont systemFontOfSize:15 *kAppScale];
    [rightButton setTitleColor:[UIColor darkTextColor] forState:UIControlStateHighlighted];
    [rightButton setBackgroundImage:[UIImage imageNamed:@"icon_rightItemBg"] forState:UIControlStateHighlighted];
    [rightButton setAdjustsImageWhenDisabled:NO];
    [rightButton addTarget:self action:@selector(navigationRightButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = rightItem;
}
#pragma mark - 子类重写

-(FXTNavType)getNavType {
    return FXTNavTypeNoRightItem;
}

-(NSString *)customNavigationRightItemTitle {
    return @"设置";
}

-(NSString *)customNavigationTitleViewTitleStr {
    return self.title;
}
- (void)navigationLeftButtonClick:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)navigationRightButtonClick:(id)sender
{
    
}
-(NSDictionary *)Style{
    NSDictionary *style=@{
                          @"body":[UIFont systemFontOfSize:12*kAppScale],
                          @"Big":[UIFont systemFontOfSize:14*kAppScale],
                          @"mainColor":@[[UIColor colorWithRed:241/255.0 green:61/255.0 blue:37/255.0 alpha:1],[UIFont fontWithName:@"HelveticaNeue" size:15*kAppScale]],
                          @"mainColor12":@[[UIColor colorWithRed:241/255.0 green:61/255.0 blue:37/255.0 alpha:1],[UIFont fontWithName:@"HelveticaNeue" size:12*kAppScale]],
                          @"mainColorershou":@[[UIColor colorWithRed:241/255.0 green:61/255.0 blue:37/255.0 alpha:1],[UIFont fontWithName:@"HelveticaNeue" size:14*kAppScale]],
                          @"matchColor":@[[UIColor colorWithRed:255/255.0 green:90/225.0 blue:36/255.0 alpha:1],[UIFont fontWithName:@"HelveticaNeue" size:15*kAppScale]],
                          @"blackColor":@[[UIColor colorWithRed:51/255.0 green:51/225.0 blue:51/255.0 alpha:1],[UIFont fontWithName:@"HelveticaNeue" size:15*kAppScale]],
                          @"smallmainColor":@[[UIColor colorWithRed:241/255.0 green:61/255.0 blue:37/255.0 alpha:1],[UIFont fontWithName:@"HelveticaNeue" size:11*kAppScale]],
                          @"smallmainColor13":@[[UIColor colorWithRed:241/255.0 green:61/255.0 blue:37/255.0 alpha:1],[UIFont fontWithName:@"HelveticaNeue" size:13*kAppScale]],
                          @"bigmainColor":@[[UIColor colorWithRed:57/255.0 green:184/225.0 blue:86/255.0 alpha:1],[UIFont fontWithName:@"HelveticaNeue" size:20*kAppScale]],
                          @"defaultmatch":@[[UIColor colorWithRed:255/255.0 green:90/225.0 blue:36/255.0 alpha:1],[UIFont systemFontOfSize:13*kAppScale]],
                          @"red15":@[[UIColor redColor],[UIFont systemFontOfSize:15*kAppScale]],
//                          @"huise":@[black153Color,[UIFont systemFontOfSize:12*kAppScale]],
//                          @"huise102":@[black102color,[UIFont systemFontOfSize:12*kAppScale]],
                           @"red11":@[redTextColor,[UIFont systemFontOfSize:11*kAppScale]],
                           @"red12":@[redTextColor,[UIFont systemFontOfSize:12*kAppScale]],
                          @"red13":@[redTextColor,[UIFont systemFontOfSize:13*kAppScale]],
                          @"red14":@[redTextColor,[UIFont systemFontOfSize:14*kAppScale]],
                          @"huise14":@[grayTextColor,[UIFont systemFontOfSize:14*kAppScale]],
                          @"heise14":@[blackTextColor,[UIFont systemFontOfSize:14*kAppScale]],
                          @"heise":@[blackTextColor,[UIFont systemFontOfSize:12*kAppScale]],
                          @"heise13":@[blackTextColor,[UIFont systemFontOfSize:13*kAppScale]],
                          
                          @"white15":@[[UIColor whiteColor],[UIFont systemFontOfSize:15*kAppScale]],
                          @"white20":@[[UIColor whiteColor],[UIFont systemFontOfSize:20*kAppScale]],
                          @"orange30":@[[UIColor colorWithRed:252/255.0 green:103/255.0 blue:30/255.0 alpha:1],[UIFont boldSystemFontOfSize:14*kAppScale]],
                          };
    return style;
}
-(NSString *)timeWithDate:(NSDate *)date{
    
    NSDateFormatter *fo = [NSDateFormatter new];
    [fo setDateFormat:@"yyyy-MM-dd"];
    NSString *da = [fo stringFromDate:date];
    NSDate *d = [fo dateFromString:da];
    return [fo stringFromDate:d];
}
@end
